package com.turtle3d.gui.console;

import java.awt.BorderLayout;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class ConsolePanel extends javax.swing.JPanel implements Console {
	private JScrollPane jScrollPane1;

	private JTextPane jTextPane1;

	/**
	 * Auto-generated main method to display this JPanel inside a new JFrame.
	 */
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new ConsolePanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}

	public ConsolePanel() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			GridBagLayout thisLayout = new GridBagLayout();
			thisLayout.rowWeights = new double[] { 0.1 };
			thisLayout.rowHeights = new int[] { 7 };
			thisLayout.columnWeights = new double[] { 0.1 };
			thisLayout.columnWidths = new int[] { 7 };
			this.setLayout(thisLayout);			
			{
				jScrollPane1 = new JScrollPane();
				this.add(jScrollPane1, new GridBagConstraints(0, 0, 1, 1, 0.0,
						0.0, GridBagConstraints.CENTER,
						GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0,
						0));
				{
					jTextPane1 = new JTextPane();
					jScrollPane1.setViewportView(jTextPane1);
					jTextPane1.setEditable(false);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void println(String message, int type) {
		String typeLabel="";
		
		if(type==INFO)
			typeLabel="INFO";
		else if(type==WARNING)
			typeLabel="WARN";
		else if(type==Console.ERROR)
			typeLabel="ERROR";						
		
		jTextPane1.setText(jTextPane1.getText()+"["+typeLabel+"] "+message+"\n");
		
		jTextPane1.setCaretPosition( jTextPane1.getDocument().getLength() );
	}

}
